const { strict } = require( "jade/lib/doctypes" );
var express = require('express');
var router = express.Router();

let {UserModel, DengjiModel, YuyueModel} = require('../model/model/xin.js')


// 王佑新路由 获取待办事项所有用户数据
router.get('/list', async function(req, res, next) {
    try {
        let result = await UserModel.find()

        let data = {
            code: 200,
            msg: '获取成功',
            result: result,
        }
        res.send(data)
  
    } catch (error) {
        console.log(error)
        let data = {
            code: 500,
            msg: '获取失败',
            result: [],
        }
        res.send(data)

    }
});

// 获取任务详情数据
router.get('/xiangqing', async function(req, res, next) {
    try {
        let { id } = req.query
        let result = await UserModel.findOne({ _id: id })
        console.log(result, '任务详情数据')

        let data = {
            code: 200,
            msg: '获取成功',
            result: result,
        }
        res.send(data)

    } catch (error) {
        console.log(error)
        let data = {
            code: 500,
            msg: '获取失败',
            result: [],
        }
        res.send(data)
    }
});

// 获取历史页面测量详情数据
router.get('/lishixiangqing', async function(req, res, next) {
    try {
        let { id } = req.query
        let result = await UserModel.findOne({ _id: id })
        console.log(result, '测量详情数据')

        let data = {
            code: 200,
            msg: '获取成功',
            result: result,
        }
        res.send(data)

    } catch (error) {
        console.log(error)
        let data = {
            code: 500,
            msg: '获取失败',
            result: [],
        }
        res.send(data)
    }
});

// 登记用户的数据
router.get('/dengji', async function(req, res, next) {
    try {
        let result = await DengjiModel.find()

        let data = {
            code: 200,
            msg: '获取成功',
            result: result,
        }
        res.send(data)
  
    } catch (error) {
        console.log(error)
        let data = {
            code: 500,
            msg: '获取失败',
            result: [],
        }
        res.send(data)
    }
});

// 预约用户的数据
router.get('/yuyue', async function(req, res, next) {
    try {
        let result = await YuyueModel.find()

        let data = {
            code: 200,
            msg: '获取成功',
            result: result,
        }
        res.send(data)
  
    } catch (error) {
        console.log(error)
        let data = {
            code: 500,
            msg: '获取失败',
            result: [],
        }
        res.send(data)
    }
});



module.exports = router;
